﻿using System.Collections.Generic;
using System.Linq;
using JStore.Core.Entities;
using SpeadFrm.ORM;

namespace JStore.Data.Daos
{
    /// <summary>
    ///
    /// </summary>
    public class PowersDao : BaseDao<Powers>
    {
        public List<Powers> GetListByMenuId(int menuId)
        {
            var sql = Sql.Builder.Where("MenuId = @0", menuId);
            return Query(sql).ToList();
        }

        public void DeleteByPowerId(int powerId)
        {
            var sql = Sql.Builder.Where("PowerId = @0", powerId);
            Delete(sql);
        }

        public List<Powers> GetAll()
        {
            var sql = Sql.Builder.Where("1=1");
            return Query(sql).ToList();
        }

        public Powers Get(string controllerName, string actionName)
        {
            var sql = Sql.Builder.Where("Controller = @0 AND Action = @1", controllerName, actionName);
            return FirstOrDefault(sql);
        }
    }
}

